package everyday.apr;

import java.util.Arrays;

/**
 * 806. 写字符串需要的行数
 */
public class Day12 {
    public static void main(String[] args) {
        int[] widths = new int[26];
        Arrays.fill(widths, 10);
        int[] lines = numberOfLines(widths, "abcdefghijklmnopqrstuvwxyz");
        System.out.println(Arrays.toString(lines));
    }

    /**
     * 遍历
     */
    public static int[] numberOfLines(int[] widths, String s) {
        int sum = 0;
        int line = 1;
        char[] chars = s.toCharArray();
        for (char c : chars) {
            if (sum + widths[c - 'a'] > 100) {
                sum = widths[c - 'a'];
                line++;
            } else {
                sum += widths[c - 'a'];
            }
        }
        return new int[]{line, sum};
    }
}
